#include <bits/stdc++.h>

using namespace std;

class ThroneInheritancex {
    unordered_map<string, int> mp1;
    unordered_map<int, string> mp2;
    int D;
    unordered_map<int, vector<int> > vec;
    unordered_set<int> dead;
    void traverse(int cur, vector<string>& ans){
        if (!dead.count(cur)) ans.push_back(mp2[cur]);
        for (int x: vec[cur])
            traverse(x, ans);
    }
public:
    ThroneInheritancex(string kingName) {
        D = 0;
        mp1[kingName] = ++D;
        mp2[D] = kingName;
        vec[D] = vector<int>();
        dead.clear();
    }
    
    void birth(string parentName, string childName) {
        int idfa = mp1[parentName];
        mp1[childName] = ++D;
        mp2[D] = childName;
        vec[D] = vector<int>();
        vec[idfa].push_back(D);
    }
    
    void death(string name) {
        dead.insert(mp1[name]);
    }
    
    vector<string> getInheritanceOrder() {
        vector<string> res;
        traverse(1, res);
        return res;
    }
};

class ThroneInheritance {
    unordered_map<string,int> mp1;
    unordered_map<int,string> mp2;
    unordered_map<int,vector<int>> childs;
    unordered_set<int> dead;
    int index;

    void traverse(int cur, vector<string>& ans){
        if (!dead.count(cur)) ans.push_back(mp2[cur]);
        for (int x: childs[cur])
            traverse(x, ans);
    }
public:
    ThroneInheritance(string kingName) {
        index=0;
        mp1[kingName]=++index;
        mp2[index]=kingName;
        childs[index]=vector<int>();
        dead.clear();
    }
    
    void birth(string parentName, string childName) {
        int id=mp1[parentName];
        mp1[childName]=++index;
        mp2[index]=childName;
        childs[index]=vector<int>();
        childs[id].push_back(index);
    }
    
    void death(string name) {
        dead.insert(mp1[name]);
    }
    
    vector<string> getInheritanceOrder() {
        vector<string> res;
        traverse(1, res);
        return res;
    }
};

/**
 * Your ThroneInheritance object will be instantiated and called as such:
 * ThroneInheritance* obj = new ThroneInheritance(kingName);
 * obj->birth(parentName,childName);
 * obj->death(name);
 * vector<string> param_3 = obj->getInheritanceOrder();
 */

int main(){
#ifdef DEBUG
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
 
 

    return 0;
}